//
//  HMComposeToolBar.swift
//  WeiBo
//
//  Created by 李立达 on 15/12/16.
//  Copyright © 2015年 heima11. All rights reserved.
//

import UIKit
enum HMcomPosebutton: Int{
    case picture = 0
    case mention = 1
    case Trend = 2
    case Emotion = 3
    case Add = 4
}




class HMComposeToolBar: UIStackView {
    
var buttomClick: ((type: HMcomPosebutton)->())?
  override init(frame: CGRect) {
        super.init(frame: frame)
    
        axis = .Horizontal
        distribution = .FillEqually
        setupUI()
    }
  required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
  }
   
    func setupUI(){
    
        addButton("compose_toolbar_picture",type: .picture)
 addButton("compose_mentionbutton_background",type: .mention)
    addButton("compose_trendbutton_background",type: .Trend)
    addButton("compose_emoticonbutton_background",type: .Emotion)
        addButton("compose_camerabutton_background",type: .Add)
    }
   
    func addButton(imagname:String,type:HMcomPosebutton){
        let button = UIButton()
        
        button.tag = type.rawValue
        button.setImage(UIImage(named: imagname), forState: .Normal)
        button.setImage(UIImage(named: "\(imagname)_highlighted"), forState: UIControlState.Highlighted)
        button.backgroundColor = UIColor(patternImage: UIImage(named: "compose_toolbar_background")!)
        button.addTarget(self, action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside)
        addArrangedSubview(button)
    }
    
    func buttonClick(button:UIButton){
    buttomClick?(type: HMcomPosebutton(rawValue: button.tag)!)
    }
}
